<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
<title></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div class="document">


<img alt="images/driebit_logo.gif" src="images/driebit_logo.gif" />
<div class="section" id="lypo-javascript-api">
<h1><a class="toc-backref" href="#id2">LYPO / Javascript API</a></h1>
<p>di 09 jun 2009 14:03:55 CEST- 14:03</p>
<div class="contents topic" id="inhoud">
<p class="topic-title first">Inhoud</p>
<ul class="simple">
<li><a class="reference internal" href="#lypo-javascript-api" id="id2">LYPO / Javascript API</a><ul>
<li><a class="reference internal" href="#inleiding" id="id3">Inleiding</a></li>
<li><a class="reference internal" href="#requests" id="id4">Requests</a></li>
<li><a class="reference internal" href="#response" id="id5">Response</a></li>
<li><a class="reference internal" href="#authenticatie" id="id6">Authenticatie</a></li>
<li><a class="reference internal" href="#opposite-score-berekenen" id="id7">Opposite score berekenen</a></li>
<li><a class="reference internal" href="#data-api" id="id8">Data API</a><ul>
<li><a class="reference internal" href="#gebruikers-functies" id="id9">Gebruikers functies</a><ul>
<li><a class="reference internal" href="#apibase-user-get" id="id10">/api.php/user/get</a></li>
<li><a class="reference internal" href="#apibase-user-create" id="id11">/api.php/user/create</a></li>
<li><a class="reference internal" href="#apibase-user-update" id="id12">/api.php/user/update</a></li>
<li><a class="reference internal" href="#apibase-user-delete" id="id13">/api.php/user/delete</a></li>
<li><a class="reference internal" href="#apibase-user-addopposite" id="id14">/api.php/user/addopposite</a></li>
<li><a class="reference internal" href="#apibase-user-removeopposite" id="id15">/api.php/user/removeopposite</a></li>
<li><a class="reference internal" href="#apibase-user-networkcode" id="id16">/api.php/user/networkcode</a></li>
<li><a class="reference internal" href="#apibase-user-networkmerge" id="id17">/api.php/user/networkmerge</a></li>
</ul>
</li>
<li><a class="reference internal" href="#stellingen-functies" id="id18">Stellingen functies</a><ul>
<li><a class="reference internal" href="#apibase-statement-list" id="id19">/api.php/statement/list</a></li>
<li><a class="reference internal" href="#apibase-statement-get" id="id20">/api.php/statement/get</a></li>
<li><a class="reference internal" href="#apibase-statement-saveanswer" id="id21">/api.php/statement/saveanswer</a></li>
</ul>
</li>
<li><a class="reference internal" href="#reactie-functies" id="id22">Reactie functies</a><ul>
<li><a class="reference internal" href="#apibase-reaction-save" id="id23">/api.php/reaction/save</a></li>
<li><a class="reference internal" href="#apibase-reaction-respect" id="id24">/api.php/reaction/respect</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#frontend-views-api" id="id25">Frontend / Views API</a><ul>
<li><a class="reference internal" href="#register" id="id26">Register</a></li>
<li><a class="reference internal" href="#widget-home" id="id27">Widget home</a><ul>
<li><a class="reference internal" href="#home-debates" id="id28">/home/debates</a></li>
<li><a class="reference internal" href="#home-opposites" id="id29">/home/opposites</a></li>
</ul>
</li>
<li><a class="reference internal" href="#debates" id="id30">Debates</a><ul>
<li><a class="reference internal" href="#debate-byname-byday" id="id31">/debate/(byname|byday)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#debate" id="id32">Debate</a></li>
<li><a class="reference internal" href="#my-profile" id="id33">My Profile</a></li>
</ul>
</li>
<li><a class="reference internal" href="#data-structuren" id="id34">Data structuren</a><ul>
<li><a class="reference internal" href="#lypouser" id="id35">LypoUser</a></li>
<li><a class="reference internal" href="#lypoopposite" id="id36">LypoOpposite</a></li>
<li><a class="reference internal" href="#statement" id="id37">Statement</a></li>
<li><a class="reference internal" href="#answer" id="id38">Answer</a></li>
<li><a class="reference internal" href="#comment" id="id39">Comment</a></li>
<li><a class="reference internal" href="#lyporesult" id="id40">LypoResult</a></li>
</ul>
</li>
<li><a class="reference internal" href="#errors" id="id41">Errors</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="inleiding">
<h2><a class="toc-backref" href="#id3">Inleiding</a></h2>
<p>Dit document geeft uitleg over welke calls er gemaakt kunnen worden door de LYPO gadget naar de backend.</p>
</div>
<div class="section" id="requests">
<h2><a class="toc-backref" href="#id4">Requests</a></h2>
<ul class="simple">
<li>Alle request gebeuren met simpele HTTP GET requests.</li>
</ul>
</div>
<div class="section" id="response">
<h2><a class="toc-backref" href="#id5">Response</a></h2>
<ul class="simple">
<li>Alle reponses zijn in JSON formaat met een vaste structuur.</li>
</ul>
</div>
<div class="section" id="authenticatie">
<h2><a class="toc-backref" href="#id6">Authenticatie</a></h2>
<p>In principe is het mogelijk om gebruikers data op te vragen mits je zijn container id en userid (op de container) weet, EN deze user ook een LYPO gebruiker is.
Maar in principe wordt er geen gevoelige informatie teruggegeven.
Alleen bij het modificeren van gegevens is het zaak nader te kijken hoe we misbruik kunnen voorkomen..</p>
<p>Is er wat te doen met een voorgedefinieerde App data instelling (private key..)</p>
</div>
<div class="section" id="opposite-score-berekenen">
<h2><a class="toc-backref" href="#id7">Opposite score berekenen</a></h2>
<p>Voor het berekenen van een lijst met opposites zijn we tot de volgende oplossing gekomen.
We weten iemand zijn eigen &quot;lypo signature&quot;. Om vervolgens een lijstje met opposites te krijgen zoeken we vai FULLTEXT (IN BOOLEAN MODE) naar de tegenovergestelde signature.
Dus:</p>
<p>Indien: a=EENS, B=GEEN MENING c=ONEENS
Mijn signatyure: &quot;1a 2c 3c 4a 5b&quot;</p>
<p>Dan zoeken we naar: 1c 2a 3a 4c&quot; (alle b antwoorden tellen we niet mee omdat dat niet uitmaakt voor de &quot;oppositeness&quot;)</p>
<pre class="literal-block">
SELECT *, MATCH(lypo_signature) AGAINST('&lt;tegenovergestelde signature&gt;' IN BOOLEAN MODE) as score FROM user ORDER BY score DESC LIMIT 20
</pre>
<ul class="simple">
<li>Antwoorden waar het antwoord: &quot;geen antwoord&quot; op is, NIET opslaan in signature, ze zijn niet relevant.</li>
</ul>
<p>Een belangrijk onderdeel van de LYPO gadget en de technische punten die getackled moeten worden, is het berekenen van de &quot;opposite score&quot; tussen gebruikers onderling.</p>
<ul>
<li><p class="first">Levenstein algoritme</p>
</li>
<li><p class="first">Needleman-Wunsch algorithm</p>
<p>** <a class="reference external" href="http://www.ludwig.edu.au/course/lectures2005/Likic.pdf">http://www.ludwig.edu.au/course/lectures2005/Likic.pdf</a></p>
</li>
</ul>
<p><strong>Vragen</strong>:</p>
<ul class="simple">
<li>Hoe beveiligen we gegevens van de buitenwereld?</li>
<li>Iets doen met een public en private key ?<ul>
<li>Voorbeelden van hoe anderen dit doen?</li>
</ul>
</li>
</ul>
<p>Zie: <a class="reference external" href="http://wiki.opensocial.org/index.php?title=Validating_Signed_Requests">http://wiki.opensocial.org/index.php?title=Validating_Signed_Requests</a></p>
<p>Leesvoer: <a class="reference external" href="http://hyper.to/blog/link/opensocial-insecurity-no-user-to-app-authentication/">http://hyper.to/blog/link/opensocial-insecurity-no-user-to-app-authentication/</a></p>
</div>
<div class="section" id="data-api">
<h2><a class="toc-backref" href="#id8">Data API</a></h2>
<p>Alle calls hebben als baseurl: /api.php</p>
<div class="section" id="gebruikers-functies">
<h3><a class="toc-backref" href="#id9">Gebruikers functies</a></h3>
<div class="section" id="apibase-user-get">
<h4><a class="toc-backref" href="#id10">/api.php/user/get</a></h4>
<p>params:</p>
<pre class="literal-block">
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt; (e946d359b363cw95&#64;hyves.nl)
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult met:
  data.user: LypoUser
</pre>
</div>
<div class="section" id="apibase-user-create">
<h4><a class="toc-backref" href="#id11">/api.php/user/create</a></h4>
<p>params:</p>
<pre class="literal-block">
VERPLICHT:
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
name: &lt;naam om als LYPO gebruiker te gebruiken&gt;

OPTIONEEL:
age:
thumbnail_url: volledige url naar profile picture (120x120)
gender: &quot;m&quot; of &quot;f&quot;
city: string
country: string
enemy: string9128)
occupation: string(128)
origin: string(128)
lypo_signature: string =&gt; &quot;1a 2b 3a 4c&quot; etc met minimaal 20 antwoorden.
  a = EENS
  b = GEEN MENING / SKIP
  c = ONEENS
keywords: string met keywords, gescheiden door een pipe teken &quot;|&quot;
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult with:
  data.user: LypoUser
</pre>
</div>
<div class="section" id="apibase-user-update">
<h4><a class="toc-backref" href="#id12">/api.php/user/update</a></h4>
<p>Update fields of LypoUser record</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
REQUIRED:
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;

OPTIONEEL:
zie de velden bij user create ...
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult with:
  data.user: LypoUser
</pre>
</div>
<div class="section" id="apibase-user-delete">
<h4><a class="toc-backref" href="#id13">/api.php/user/delete</a></h4>
<p>Delete LypoUser record and all other data for this user: USE WITH CARE!</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
REQUIRED:
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult
</pre>
</div>
<div class="section" id="apibase-user-addopposite">
<h4><a class="toc-backref" href="#id14">/api.php/user/addopposite</a></h4>
<p>Add a user as a perfect opposite of another user</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
REQUIRED:
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
opposite_id: id of the user that needs to be a perfect opposite.
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult
</pre>
</div>
<div class="section" id="apibase-user-removeopposite">
<h4><a class="toc-backref" href="#id15">/api.php/user/removeopposite</a></h4>
<p>Removes linkage between user and other user as perfect opposites</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
REQUIRED:
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
opposite_id: id of the currenlty linked perfect opposite
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult
</pre>
</div>
<div class="section" id="apibase-user-networkcode">
<h4><a class="toc-backref" href="#id16">/api.php/user/networkcode</a></h4>
<p>Creates a network code for merging/connecting two LYPO accounts with each other.
This requires a signed request!</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
REQUIRED:
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult with:
  data.code: &lt;code&gt; (valid only 1 hour!)
</pre>
</div>
<div class="section" id="apibase-user-networkmerge">
<h4><a class="toc-backref" href="#id17">/api.php/user/networkmerge</a></h4>
<p>Merges another LYPO installation with the current installation with the irght code that was generated woth the /uer/networkcode call
This requires a signed request!</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
REQUIRED:
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
code: string that was generated on the other network
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult
</pre>
</div>
</div>
<div class="section" id="stellingen-functies">
<h3><a class="toc-backref" href="#id18">Stellingen functies</a></h3>
<div class="section" id="apibase-statement-list">
<h4><a class="toc-backref" href="#id19">/api.php/statement/list</a></h4>
<p>Retruns all LYPO statements available</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
none
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoStatement[]  (array)
</pre>
</div>
<div class="section" id="apibase-statement-get">
<h4><a class="toc-backref" href="#id20">/api.php/statement/get</a></h4>
</div>
<div class="section" id="apibase-statement-saveanswer">
<h4><a class="toc-backref" href="#id21">/api.php/statement/saveanswer</a></h4>
<p>Het opslaan van een antwoord op een stelling update automatisch de &quot;lypo_signature&quot; van de betreffende gebruiker</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
VERPLICHT:
statement_id:  &lt;id van statement&gt;
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
answer: a,b of c
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult
  data.lypo_signature: Geupdate signature voor gebruiker
  message: OK indien gelukt
</pre>
</div>
</div>
<div class="section" id="reactie-functies">
<h3><a class="toc-backref" href="#id22">Reactie functies</a></h3>
<div class="section" id="apibase-reaction-save">
<h4><a class="toc-backref" href="#id23">/api.php/reaction/save</a></h4>
<p>Het opslaan van een reactie op een stelling</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
VERPLICHT:
statement_id:  &lt;id van statement&gt;
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
content: tekst van reactie (incl. embed codes?)

OPTIONEEL:
embed_code: video embed code (youtube only for now)
embed_link: video url (youtube only for now)
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult
</pre>
</div>
<div class="section" id="apibase-reaction-respect">
<h4><a class="toc-backref" href="#id24">/api.php/reaction/respect</a></h4>
<p>Geeft een reactie respect (dit kan 1x per gebruiker per reactie)</p>
<p><strong>params:</strong></p>
<pre class="literal-block">
VERPLICHT:
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt;
reaction_id:  &lt;id van reactie&gt;
</pre>
<p><strong>returns:</strong></p>
<pre class="literal-block">
LypoResult
</pre>
</div>
</div>
</div>
<div class="section" id="frontend-views-api">
<h2><a class="toc-backref" href="#id25">Frontend / Views API</a></h2>
<p>Alle calls hebben als baseurl: /frontend.php</p>
<div class="section" id="register">
<h3><a class="toc-backref" href="#id26">Register</a></h3>
<p>Heeft geen view, staat inline in de gadget.</p>
</div>
<div class="section" id="widget-home">
<h3><a class="toc-backref" href="#id27">Widget home</a></h3>
<p>Heeft twee subviews: debates en opposites</p>
<div class="section" id="home-debates">
<h4><a class="toc-backref" href="#id28">/home/debates</a></h4>
<p>Geeft alle debates tabs in 1x terug:</p>
<ul class="simple">
<li>Debate of the day</li>
<li>Recent debates</li>
<li>Respected debates</li>
</ul>
<pre class="literal-block">
/frontend.php/home/debates
</pre>
<p><strong>params:</strong>:</p>
<pre class="literal-block">
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt; (e946d359b363cw95&#64;hyves.nl)
</pre>
</div>
<div class="section" id="home-opposites">
<h4><a class="toc-backref" href="#id29">/home/opposites</a></h4>
<pre class="literal-block">
/frontend.php/home/opposites
</pre>
<p><strong>params:</strong>:</p>
<pre class="literal-block">
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt; (e946d359b363cw95&#64;hyves.nl)
</pre>
</div>
</div>
<div class="section" id="debates">
<h3><a class="toc-backref" href="#id30">Debates</a></h3>
<div class="section" id="debate-byname-byday">
<h4><a class="toc-backref" href="#id31">/debate/(byname|byday)</a></h4>
<p>Geeft beide debates tabs terug, maar afhankelijk van welke view is meegegeven, is één van de twee actief</p>
<pre class="literal-block">
/frontend.php/debates/byday
/frontend.php/debates/byname
</pre>
<p><strong>params:</strong>:</p>
<pre class="literal-block">
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt; (e946d359b363cw95&#64;hyves.nl)
</pre>
</div>
</div>
<div class="section" id="debate">
<h3><a class="toc-backref" href="#id32">Debate</a></h3>
<p>Debate pagina heeft twee subviews, main (de statement +_ video) en reacties op de het statement</p>
<pre class="literal-block">
/frontend.php/debate/main
/frontend.php/debate/reactions
/frontend.php/debate/reactions
</pre>
<p><strong>params:</strong>:</p>
<pre class="literal-block">
userid:  &lt;userid_on_container&gt;&#64;&lt;container_string&gt; (e946d359b363cw95&#64;hyves.nl)
statement_id: &lt;statement_id&gt; of debate to show
</pre>
</div>
<div class="section" id="my-profile">
<h3><a class="toc-backref" href="#id33">My Profile</a></h3>
</div>
</div>
<div class="section" id="data-structuren">
<h2><a class="toc-backref" href="#id34">Data structuren</a></h2>
<p>Bijna alle API calls geven gestructureerde data terug.</p>
<div class="section" id="lypouser">
<h3><a class="toc-backref" href="#id35">LypoUser</a></h3>
<p>Het generieke LYPO account waar alles onder geschaard wordt.</p>
<pre class="literal-block">
LypoUser
  id:
  name: &lt;naam die bij eerste account-creatie wordt gebruikt vanuit de betreffende container&gt;
  email: &lt;email die bij eerste account-creatie wordt gebruikt vanuit de betreffende container&gt;
  city: &lt;plaats die bij eerste account-creatie wordt gebruikt vanuit de betreffende container&gt;
  country: &lt;land die bij eerste account-creatie wordt gebruikt vanuit de betreffende container&gt;
  respects: aantal respects wat gebruiker heeft gekregen
  num_opposites: aantal opposites die de gebruiker heeft
  opposites:
    --&gt; LypoOpposite[] array met LypoOpposites voor deze gebruiker
</pre>
</div>
<div class="section" id="lypoopposite">
<h3><a class="toc-backref" href="#id36">LypoOpposite</a></h3>
<p>Zelfde als LypoUser, met 1 extra property, namelijk:</p>
<pre class="literal-block">
LypoOpposite
 &lt;alle LypoUser properties&gt;
 opposite_percentage: 0 - 100%
</pre>
</div>
<div class="section" id="statement">
<h3><a class="toc-backref" href="#id37">Statement</a></h3>
<p>Een stelling.</p>
</div>
<div class="section" id="answer">
<h3><a class="toc-backref" href="#id38">Answer</a></h3>
<p>Een antwoord op een stelling.</p>
</div>
<div class="section" id="comment">
<h3><a class="toc-backref" href="#id39">Comment</a></h3>
<p>Een reactie op een antwoord op een stelling.</p>
</div>
<div class="section" id="lyporesult">
<h3><a class="toc-backref" href="#id40">LypoResult</a></h3>
<pre class="literal-block">
LypoResult:
 - error: true / false
 - message: &lt;bericht met details over fout of success&gt;
 - data
       - ... Kan van alles zijn zie calls
</pre>
</div>
</div>
<div class="section" id="errors">
<h2><a class="toc-backref" href="#id41">Errors</a></h2>
<p><a class="reference external" href="mailto:hidde&#64;driebit.nl">Hidde Braun</a></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Version:</th><td class="field-body">1.0</td>
</tr>
<tr class="field"><th class="field-name">Author:</th><td class="field-body"><a class="reference external" href="mailto:hidde&#64;driebit.nl">Hidde Braun</a></td>
</tr>
<tr class="field"><th class="field-name">Author:</th><td class="field-body"><a class="reference external" href="mailto:sjors&#64;driebit.nl">Sjors Rijsdam</a></td>
</tr>
<tr class="field"><th class="field-name">Company:</th><td class="field-body"><a class="reference external" href="http://www.driebit.nl">Driebit</a></td>
</tr>
<tr class="field"><th class="field-name">Date:</th><td class="field-body">di 09 jun 2009 14:03:55 CEST</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
